﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Custom="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit" xmlns:ViewModel1="clr-namespace:LightningTools.BCSTesterMan.ViewModel;assembly=LightningTools.BCSTesterMan.ViewModel" xmlns:LightningTools_BCSTesterMan="clr-namespace:LightningTools.BCSTesterMan" x:Class="LightningTools.BCSTesterMan.View.MethodDetailView" mc:Ignorable="d" >

	<UserControl.Resources>
		<Style x:Key="gpRequestStyle" TargetType="{x:Type GroupBox}">
			<Style.Triggers>
				<DataTrigger Binding="{Binding ActiveMethod.HasParameters}" Value="false">
					<Setter Property="Visibility" Value="Collapsed" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<Style x:Key="gpResponseStyle" TargetType="{x:Type GroupBox}">
			<Style.Triggers>
				<DataTrigger Binding="{Binding ActiveMethod.HasResponse, UpdateSourceTrigger=PropertyChanged}" Value="false">
					<Setter Property="Visibility" Value="Collapsed" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<Style x:Key="btnIsSupportedMethod" TargetType="{x:Type Button}">
			<Style.Triggers>
				<DataTrigger Binding="{Binding ActiveMethod.IsSupported, UpdateSourceTrigger=PropertyChanged}" Value="false">
					<Setter Property="Visibility" Value="Collapsed" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<Style x:Key="IsInvokingMethodStyle" TargetType="{x:Type LightningTools_BCSTesterMan:LoadingSpinner}">
			<Style.Triggers>
				<DataTrigger Binding="{Binding IsInvokingMethod, UpdateSourceTrigger=PropertyChanged}" Value="false">
					<Setter Property="Visibility" Value="Collapsed" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<Style x:Key="ValueCellStyle" TargetType="{x:Type Custom:DataGridCell}">
			<Setter Property="Background" Value="#00beef" />
		</Style>

	</UserControl.Resources>

	<StackPanel x:Name="MethodDetailStackPanel" d:DataContext="{d:DesignInstance {x:Type ViewModel1:MainWindowViewModel}}">
		<GroupBox Header="Method Details" Margin="8">
			<Grid x:Name="MethodInformationGrid">
				<Grid.RowDefinitions>
					<RowDefinition Height="auto" />
					<RowDefinition Height="auto" />
				</Grid.RowDefinitions>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="auto" />
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>
				<Label Content="Method Name:" FontWeight="Black" Grid.Row="0" VerticalAlignment="Center" />
				<TextBlock Text="{Binding ActiveMethod.Name, FallbackValue=Method Name}" Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" />
				<Label Content="Type:" FontWeight="Black" Grid.Row="1" VerticalAlignment="Center" />
				<TextBlock Text="{Binding ActiveMethod.MethodType, FallbackValue=Method Type}" Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" />
			</Grid>
		</GroupBox>

		<GroupBox x:Name="MethodRequestGroupBox" Header="Request" Margin="8" Style="{StaticResource gpRequestStyle}">
			<StackPanel>
				<Label Content="Please enter input parameters." />
				<Custom:DataGrid x:Name="RequestDataGrid" CanUserAddRows="False" ItemsSource="{Binding ActiveMethod.Parameters}" AutoGenerateColumns="False" SelectionMode="Single" ColumnWidth="SizeToHeader" Margin="8">
					<Custom:DataGrid.Columns>
						<Custom:DataGridTextColumn Binding="{Binding Name}" Width="auto" Header="Name" IsReadOnly="True" />
						<Custom:DataGridTextColumn Binding="{Binding Type}" Width="auto" Header="Type" IsReadOnly="True" />
						<Custom:DataGridTextColumn Binding="{Binding Value}" Width="auto" Header="Value" CellStyle="{StaticResource ValueCellStyle}" />
						<Custom:DataGridTextColumn Binding="{Binding FieldAppliedTo}" Width="auto" IsReadOnly="True" Header="Applies to Field" />
						<Custom:DataGridTextColumn Binding="{Binding Filter}" Width="auto" IsReadOnly="True" Header="Input Type" />
					</Custom:DataGrid.Columns>
				</Custom:DataGrid>
			</StackPanel>
		</GroupBox>
		<Button x:Name="InvokeMethodButton" HorizontalAlignment="Center" Content="Invoke" Margin="8,0" Command="{Binding InvokeMethodCommand}" Style="{StaticResource btnIsSupportedMethod}" />

		<LightningTools_BCSTesterMan:LoadingSpinner Width="60" Height="60" Style="{StaticResource IsInvokingMethodStyle}" />

		<GroupBox x:Name="MethodResponseGroupBox" Header="Response" Margin="8" Style="{StaticResource gpResponseStyle}">
			<StackPanel>
				<Custom:DataGrid x:Name="MethodDataDataGrid" ItemsSource="{Binding ActiveMethod.MethodResponseDetail.MethodDataView}" SelectionMode="Single" IsReadOnly="True" AutoGenerateColumns="True" Margin="8" />
			</StackPanel>
		</GroupBox>
		<GroupBox x:Name="MethodDetailGroupBox" Header="Detail" Margin="8" Style="{StaticResource gpResponseStyle}">
			<TextBlock Margin="4" x:Name="MethodDetailTextBlock" Text="{Binding ActiveMethod.MethodResponseDetail.Detail}" />
		</GroupBox>

	</StackPanel>

</UserControl>